"use strict";
import Vue from "vue";
import Router from "vue-router";
import ElementUI from 'element-ui';


import requireManage from './requireManage'
import serviceManage from './serviceManage'
import systemManage from './systemManage'
import operationManage from './operationManage'
import helpManage from './helpManage'
import taskManage from './taskManage'
import userManage from './userManage'
import orgManage from './orgManage'
import transManage from './transManage'
import store from "../store";
Vue.use(Router);
Vue.use(ElementUI);
var router;
export default (router = new Router({
	mode:'hash',
	routes: [{
			path: "",
			redirect: "/main"
		},
		{
			path: "/main",
			component: () => import("@/view/layout"),
			meta: {
				requireAuth: true, // 只要此字段为true，必须做鉴权处理
				title: "首  页",
			},
			children: [{
					path: "",
					component: () => import("@/view/home"),
					meta: { //元数据
						title: "首 页",
					},
				}, operationManage, taskManage, requireManage, serviceManage, systemManage, helpManage,
				userManage, orgManage, transManage,
				{
					path: "404",
					name: '404',
					component: () => import('@/view/notFind'),
					meta: { //元数据
						title: "404",
					},
				},
				{
					path: "*",
					redirect: '404'
				}
			],
		},
		{
			path: "/login",
			component: () => import("@/view/login"),
			meta: { //元数据
				title: "登 录",
			},
		},
		{
			path: "/404",
			name: '404',
			component: () => import('@/view/notFind'),
			meta: { //元数据
				title: "404",
			},
		},
		{
			path: "/qms",
			component: () => import("@/view/qms"),
			meta: { //元数据
				title: "qms",
			},
		},
		{
			path: "/guide",
			component: () => import("@/view/guide"),
			meta: { //元数据
				title: "帮助",
			},
		},
		{
			path: "*",
			redirect: '/404'
		}
	]
}));

router.beforeEach((to, from, next) => {
	if(to.meta.title){
		document.title = "金农云易通 | "+to.meta.title;
		
	}
	
	//if (to.matched.some(res => res.meta.requireAuth)) {
	store.commit('SET_SUBTITLE', '');
	if (store.getters.getActiveUser() == null && to.path != '/login' && to.path != '/qms') {
		next({
			path: "/login",
			params: to.params,
			query: {
				redirect: to.fullPath
			}
		});
	} else {
		
		
		/* if (!store.getters.getTabLock) { */
			next();
		/* } else {
			Vue.prototype.$confirm('离开当前页面会照成数据丢失，确认离开当前页面?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				store.dispatch('setTabLock', false);
				next();
			}).catch(() => {

			});
		} */
	}
	/* } else {
	  next();
	} */
});
